home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / GRAPH_FO / CFONTORA.C next >
Text File  |  1991-03-26  |  3KB  |  108 lines

  1. /******************************************************************************
  2.     CFontorama.c
  3.  
  4.         A panorama that supports Font and Size menus, updating them properly
  5.         in UpdateMenus().
  6.  
  7.     SUPERCLASS = CPanorama.c
  8.  
  9.     Copyright ⌐ 1991 Maarten Meijer. All rights reserved.
  10.         CIS 100016,1764; FidoNet 2:512/114
  11. *******************************************************************************/
  12.  
  13. #include <CBartender.h>
  14. #include <Commands.h>
  15.  
  16. #include "CFontorama.h"
  17.  
  18. extern CBartender    *gBartender;
  19.  
  20. /******************************************************************************
  21.     DoCommand
  22.  
  23.         Handle the font and size commands for the current garfport.
  24. *******************************************************************************/
  25.  
  26. void    CFontorama::DoCommand(long theCommand) {
  27.     Str255    itemName;
  28.     long    number;
  29.     short    fontID, fontSize;
  30.  
  31.     if (theCommand < 0) {
  32.  
  33.         switch (HiShort(-theCommand)) {
  34.  
  35.             case MENUfont:
  36.                 gBartender->GetCmdText(theCommand, itemName);
  37.                 GetFNum(itemName, &fontID);
  38.                 Prepare();
  39.                 TextFont(fontID);
  40.                 Refresh();
  41.                 break;
  42.  
  43.             case MENUsize:
  44.                 gBartender->GetCmdText(theCommand, itemName);
  45.                 StringToNum(itemName, &number);
  46.                 Prepare();
  47.                 fontSize = number;
  48.                 TextSize(fontSize);
  49.                 Refresh();
  50.                 break;
  51.  
  52.             default:
  53.                 inherited::DoCommand(theCommand);
  54.                 break;
  55.         }
  56.  
  57.     } else {
  58.  
  59.         switch(theCommand) {
  60.  
  61.             default:
  62.                 inherited::DoCommand(theCommand);
  63.                 break;
  64.             }
  65.         }
  66.     }
  67.  
  68. /******************************************************************************
  69.     UpdateMenus
  70.         Set the font and size menus to the current settings of the GrafPort.
  71.         It outlines the existing sizes for the selected font.
  72. *******************************************************************************/
  73.  
  74. void    CFontorama::UpdateMenus() {
  75.     register GrafPtr    grafPtr;
  76.     short                fontSize, fontID;
  77.     Str255                fontStr;
  78.     short                item, noItems;
  79.     long                size;
  80.     MenuHandle            menu;
  81.  
  82.     /* the font and size menus should allways be enabled */
  83.  
  84.     grafPtr = GetMacPort();
  85.     fontSize = grafPtr->txSize;
  86.     fontID = grafPtr->txFont;
  87.  
  88.     GetFontName(fontID, fontStr);
  89.     item = gBartender->FindItemText(MENUfont, fontStr);
  90.     CheckItem(GetMHandle(MENUfont), item, true);
  91.  
  92.     NumToString((long)fontSize, fontStr);
  93.     menu = GetMHandle(MENUsize);
  94.     item = gBartender->FindItemText(MENUsize, fontStr);
  95.     CheckItem(menu, item, true);
  96.  
  97.     noItems = CountMItems(menu);
  98.     for(item = 1 ; item < noItems; item++) {
  99.         GetItem(menu, item, fontStr);
  100.         StringToNum(fontStr, &size);
  101.         if( RealFont(fontID, (short)size) )
  102.             SetItemStyle(menu, item, outline);
  103.         else
  104.             SetItemStyle(menu, item, 0);
  105.         }
  106.  
  107.     inherited::UpdateMenus();
  108.     }